package com.example.parttimejob.controller;


import com.example.parttimejob.mapper.UserMapper;
import com.example.parttimejob.pojo.entity.Merchants;
import com.example.parttimejob.pojo.entity.User;
import com.example.parttimejob.pojo.entity.dto.*;
import com.example.parttimejob.pojo.entity.vo.MerchantsModifyVo;
import com.example.parttimejob.pojo.entity.vo.PartTimeJobsVo;
import com.example.parttimejob.pojo.entity.vo.UserModifyVo;
import com.example.parttimejob.pojo.entity.vo.UserPartTimeJobsVo;
import com.example.parttimejob.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/User")
//@Api("用户")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    //用户注册
    @PostMapping("/registUser/{username}/{passwd}")
    public String registUser(@PathVariable String username,@PathVariable String passwd)
    {
//        System.out.println(merchantUsername);
//        System.out.println(passwd);
        return userService.registUser(username,passwd);
    }

    //用户登录
    @GetMapping("/loginUser/{username}/{passwd}")
    public int loginUser(@PathVariable String username,@PathVariable String passwd)
    {
        return userService.loginUser(username,passwd);
    }


    //根据用户id查询用户信息
    @GetMapping("/getById/{id}")
    public User getById(@PathVariable Integer id)
    {
        return userService.getById(id);
    }

    //判断用户是否实名
    @GetMapping("/selectUserStatus/{UserId}")
    public String SelectUserStatus(@PathVariable Integer UserId)
    {
        return userService.SelectStoreStatus(UserId);
    }

   //用户实名认证
    @PostMapping("/IdeafiUser")
    public String IdeafiUser(@RequestBody UserDto userDto)
    {
        return userService.IdeafiUser(userDto);
    }

    //用户首先查询信息再修改
    @GetMapping("/SelectModify/{UserId}")
    public UserModifyVo SelectModify(@PathVariable Integer UserId){
        return userService.SelectModify(UserId);
    }

    //    用户修改信息
    @PutMapping("/ModifyUser")
    public String ModifyUser(@RequestBody UserModifyDto userModifyDto ){
        return  userService.ModifyUser(userModifyDto);
    }


    //查询所有兼职信息
    @GetMapping("/UserPartJob/{userId}")
    public List<UserPartTimeJobsVo> UserPartJob(@PathVariable Integer userId)
    {
        return userService.UserPartJob(userId);
    }


    //新增评论
    @PostMapping("/AddReview")
    private String UserAddReview(@RequestBody UserAddReviewDto userAddReviewDto)
    {
       return userService.UserAddReview(userAddReviewDto);
    }


    @Autowired
    UserMapper usermapper;

    @GetMapping("/users-including/{username}")
    public List<User> getUsersIncludingUsername(@PathVariable String username) {
        List<User> allUsers = usermapper.selectList(null);
        return allUsers.stream()
                .filter(user -> user.getUsername().equals(username))
                .collect(Collectors.toList());
    }


    @GetMapping("/users-excluding/{username}")
    public List<User> getUsersExcludingUsername(@PathVariable String username) {
        List<User> allUsers = usermapper.selectList(null);
        return allUsers.stream()
                .filter(user -> !user.getUsername().equals(username))
                .collect(Collectors.toList());
    }

    @GetMapping("")
    public List<User> getUser(){
        return usermapper.selectList(null);
    }


}
